package com.wd.tech.view.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.wd.tech.R;
import com.wd.tech.bean.ZixunBean;

import java.util.List;

public class ZixunAdapter extends RecyclerView.Adapter<ZixunAdapter.VH> {

    private Context context;
    List<ZixunBean.ResultBean> list;

    public ZixunAdapter(Context context, List<ZixunBean.ResultBean> list) {
        this.context = context;
        this.list = list;
    }

    @NonNull
    @Override
    public VH onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {

        View inflate = View.inflate(context, R.layout.item_zixun, null);

        VH vh = new VH(inflate);

        return vh;
    }

    @Override
    public void onBindViewHolder(@NonNull VH holder, int position) {

        Glide.with(context)
                .load(list.get(position).getThumbnail())
                .error(R.mipmap.ic_launcher_round)
                .placeholder(R.mipmap.ic_launcher_round)
                .into(holder.zixun_ima);


        holder.zixun_name.setText(list.get(position).getTitle());

        holder.zixun_summary.setText(list.get(position).getSummary());

        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                itemClick.setClick(list.get(position).getId());
            }
        });
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    class VH extends RecyclerView.ViewHolder {

        private final ImageView zixun_ima;
        private final TextView zixun_summary,zixun_name;

        public VH(@NonNull View itemView) {
            super(itemView);


            zixun_ima = itemView.findViewById(R.id.zixun_ima);
            zixun_summary = itemView.findViewById(R.id.zixun_summary);
            zixun_name=itemView.findViewById(R.id.zixun_name);

        }
    }



    //点赞的点击回调
    public interface ItemClick{
        void setClick(int id);
    }
    private ItemClick itemClick;
    public void setItemClick(ItemClick itemClick){
        this.itemClick=itemClick;
    }
}
